//
//  ViewController.m
//  ZZBarometer
//
//  Created by 周德艺 on 2018/7/29.
//  Copyright © 2018年 周德艺. All rights reserved.
//

#import "ViewController.h"
#import <YTKNetwork.h>
#import "ApiGetRequest.h"
#import "ApiPostRequest.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.title = @"首页";
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    NSString *urlStr = @"https://www.meix.com/iaweb/mobile/activityApp.do?clientstr={activityId:25966}";
    //转码处理
    NSString *urlStr2 = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSURL *url = [NSURL URLWithString:urlStr2];
    NSLog(@"url ----- %@",url);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    NSInteger row = indexPath.row;
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor colorWithRed:(50+8*row)/255.0
                                           green:(60+5*row)/255.0
                                            blue:(250-5*row)/255.0
                                           alpha:1.00];
//    [UIColor colorWithRed:0.15 green:0.48 blue:0.87 alpha:1.00]
    cell.textLabel.text = [NSString stringWithFormat:@"{ %ld - %ld }",indexPath.section, row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ApiGetRequest *api = [[ApiGetRequest alloc] init];
    api.apiUrl = @"/api/gate/kline";
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSLog(@"----- %@",request.responseJSONObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSLog(@"----- %@",request.error);
    }];
}

@end
